import json
import datasets
from datasets import DownloadManager,DatasetInfo

class Round1TestDataset(datasets.GeneratorBasedBuilder):
    def _info(self):
        return DatasetInfo(
            description = """
                这是一个dataset表示我参加的第一轮比赛
                """,
            # 指定该数据集的字段信息和类型(最后要处理成的形式)
            features=datasets.Features(
                {
                    "id": datasets.Value("string"),
                    "question": datasets.Value("string"),
                    # "options": datasets.features.ClassLabel(names=["0", "1"]),
                    "options": datasets.features.Sequence(datasets.Value("string"))
                }
            )
        )
    def _split_generators(self, dl_manager: DownloadManager):
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "filepath": "./round1_test_data.jsonl",
                }
            )
        ]
    def _generate_examples(self, filepath):
        filepath = "round1_test_data.jsonl"
        with open(filepath, "r", encoding="utf-8") as f:
                data = f.readlines()
                data = [i.strip() for i in data]
                id = 0
                for i in data:
                    item  = json.loads(i)
                    for question in item["questions"]:
                        id +=1
                        yield id, {
                            "id": item["id"],
                            "question": question["question"],
                            "options": question["options"]
                        }

# dateset = Round1TestDataset()
# info = dateset.info
